

// 现场模拟数据类型列表
export const sceneTypeList = [
    {
        name: '水质检测',
        type: 4,
        imgSrc:require("@/assets/images/prj/sence/drag_canre.png")
    },
    {
        name: '环境监测仪',
        type: 5,
        imgSrc:require("@/assets/images/prj/sence/drag_lift.png")
    },
    {
        name: '塔机',
        type: 6,
        imgSrc:require("@/assets/images/prj/sence/drag_gantry.png")
    },
    {
        name: '升降机',
        type: 7,
        imgSrc:require("@/assets/images/prj/sence/drag_bridge.png")
    },
    {
        name: '龙门吊',
        type: 8,
        imgSrc:require("@/assets/images/prj/sence/drag_crawler.png")
    },
    {
        name: '架桥机',
        type: 9,
        imgSrc:require("@/assets/images/prj/sence/drag_env.png")
    },
    {
        name: '履带吊',
        type: 10,
        imgSrc:require("@/assets/images/prj/sence/drag_water.png")
    },
    {
        name: '毒害气体',
        type: 12,
        imgSrc:require("@/assets/images/prj/sence/drag_gas.png")
    },
    {
        name: '视频摄像头',
        type: 20,
        imgSrc:require("@/assets/images/prj/sence/drag_fim.png")
    },
    {
        name: '智能水表',
        type: 30,
        imgSrc:require("@/assets/images/prj/sence/drag_energy_water.png")
    },
    {
        name: '智能电表',
        type: 31,
        imgSrc:require("@/assets/images/prj/sence/drag_energy_electricity.png")
    },
    {
        name: '智能电箱',
        type: 32,
        imgSrc:require("@/assets/images/prj/sence/drag_energy_box.png")
    },
];

// 现场模拟类型数据格式化
export function initSceneTypeDataFn(list){
    let results = [];
    let length = list.length;
    let hashObj = {};
    for (let i = 0; i < length; i++) {
        let item = list[i];
        // 匹配成功返回 现场模拟数据类型列表 中的某一项
        let typeObj = sceneTypeList.find(v => item.objType == v.type);
        // 匹配返回的数组里面是否存在
        let flag = results.some(v => v.id == typeObj.type);
        if(!flag){
            // 子级数据过滤
            let childList = list.filter(v => v.objType == typeObj.type);
            // 子级数据转换
            let children = initSceneChildDataFn(childList,typeObj.type);
            hashObj[typeObj.type] = {
                label:typeObj.name,
                id:typeObj.type,
                total:children.length,
                children:children,
                src:typeObj.imgSrc,
                focus:false,
            };
            results.push(hashObj[typeObj.type]);
        }
    };
    results = results.filter(v => v.children.length !== 0);
    return results
};

// 现场模拟子级数据格式化
export function initSceneChildDataFn(list,type){
    let results = [];
    let length = list.length;
    for (let i = 0; i < length; i++) {
        let id = list[i].id || list[i].objId || list[i].craneId || list[i].liftId || list[i].gantryId || list[i].bridgeId || list[i].crawlerId || list[i].waterId || list[i].electricId || list[i].boxId;
        let obj = {
            id,
            label: list[i].code || list[i].name || list[i].objName,
            pid: type,
            ids: type + '-' +  id,
        }
        results.push(obj);
    }
    return results;
};
